<?php
use classlib\core as GC;
define('OPENDEBUG', true);
define('WEBROOT', __DIR__);
define('PROJECT', 'DEVELOP');
define('COREDIR', dirname(__DIR__));
(!OPENDEBUG) && error_reporting(0);
require COREDIR.'/classlib/core/config.cls.php';
require COREDIR.'/classlib/core/router.cls.php';
require COREDIR.'/classlib/core/common.func.php';
require COREDIR.'/classlib/core/view.cls.php';
require COREDIR.'/classlib/core/model.cls.php';
try {
	spl_autoload_register('classlib\core\auto_loader');
	$ini = GC\router::__init__();
	GC\router::__run($ini);
	$middleware = array('classlib\core\middleware\log','classlib\core\middleware\http');
	GC\middleware\middleware::build($middleware)->doservice();
} catch (Exception $e) {//出现异常的时候记录错误日志
	\classlib\logger::inst()->write($e->getCode().':'.$e->getMessage(), 0);
	if (GC\router::isajax()) {
		$view = GC\view::inst('json');
		$msg  = mb_convert_encoding($e->getMessage(), 'utf-8');
		$view->assign_error($e->getCode(), $msg);
	} else {
		$view = GC\view::inst('html');
		$view->assign('msg', $e->getMessage());
		$view->display('error.html');
	}
}